<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background: #f4f4f4;
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            margin: 0;
        }

        .container {
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
            padding: 40px;
            width: 80%;
            max-width: 350px;
        }

        h1 {
            text-align: center;
            margin-bottom: 20px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 5px;
        }

        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 10px;
            border-radius: 5px;
            border: 1px solid #ddd;
            box-sizing: border-box;
        }

        input:focus {
            outline: none;
            border-color: #5c6ac4;
        }

        button {
            width: 100%;
            background-color: #5c6ac4;
            color: white;
            padding: 15px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        button:hover {
            opacity: 0.9;
        }

        p {
            text-align: center;
            margin-top: 10px;
        }

        a {
            color: #5c6ac4;
            text-decoration: none;
        }

        a:hover {
            text-decoration: underline;
        }

        .avatar-container {
            position: relative;
            width: 100px;
            height: 100px;
            margin: 20px auto;
            border-radius: 50%;
            overflow: hidden;
            cursor: pointer;
            background: #ddd;
        }

        .avatar-container img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .avatar-container input[type="file"] {
            display: none;
        }

        .avatar-label {
            display: block;
            text-align: center;
            margin-top: 10px;
            color: #5c6ac4;
            cursor: pointer;
        }

        @media (max-width: 480px) {
            .container {
                width: 95%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>注册</h1>
        {% if error %}
        <p style="color: red;">{{ error }}</p>
        {% endif %}
        <form method="POST" enctype="multipart/form-data">
            <div class="form-group">
                <div class="avatar-container">
                    <img src="{{ url_for('static', filename='avatars/default_avatar.png') }}" alt="" id="avatar-preview">
                    <input type="file" name="avatar" accept="image/*" id="avatar-input">
                </div>
                <label for="avatar-input" class="avatar-label"></label>
            </div>
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" required>
            </div>
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" required>
            </div>
            
            <button type="submit">注册</button>
        </form>
        <p>已有账号？<a href="{{ url_for('main.login') }}">登录</a></p>
    </div>
    <script>
        const avatarContainer = document.querySelector('.avatar-container');
        const avatarInput = document.getElementById('avatar-input');
        const avatarPreview = document.getElementById('avatar-preview');

        avatarContainer.addEventListener('click', () => {
            avatarInput.click();
        });

        avatarInput.addEventListener('change', (event) => {
            const file = event.target.files[0];
            if (file) {
                const reader = new FileReader();
                reader.onload = (e) => {
                    avatarPreview.src = e.target.result;
                };
                reader.readAsDataURL(file);
            }
        });
    </script>
</body>
</html>